﻿using Microsoft.Xna.Framework;
using Ultima.Xna.Data;

namespace Ultima.Xna.Graphics.UI.Gumps
{
    public class GumpLabel : GumpEntry
    {
        private int _hue = 1;
        private int _fontId = 9;

        public int FontId
        {
            get { return _fontId; }
            set { _fontId = (int)MathHelper.Clamp(value, 0, 10); }
        }

        public ASCIIFont Font
        {
            get { return ASCIIFont.GetFixed(_fontId); }

        }

        public int Hue
        {
            get { return _hue; }
            set
            {
                _hue = value;
            }
        }

        public override string Text
        {
            get
            {
                if (Dock != Dock.None)
                {
                    return Utility.WrapASCIIText(_fontId, base.Text, RenderBounds.Width);
                }

                return base.Text;
            }
            set
            {
                base.Text = value;
            }
        }

        public GumpLabel(Game game)
            : base(game)
        {
            Focusable = false;
        }

        public override void Draw(GameTime gameTime)
        {
            Manager.Renderer.Render(this);

            //ASCIIText.Inititlize(Game.GraphicsDevice);

            ////TODO: Fix fucking hueing... I'm only getting white, or black...
            //GumpEffect.Parameters["HueTexture"].SetValue(Hues.Texture);
            //GumpEffect.Parameters["Hue"].SetValue(new Vector2(Hue - 1, 0));

            //ControlRenderer.RenderASCIIText(this, GumpEffect, _font, Text);

            base.Draw(gameTime);
        }

        public override void Invalidate()
        {
            _size = new Vector2(Font.GetWidth(Text), Font.Height);

            base.Invalidate();

            Vector2 position = Position;

            if (Dock == Dock.None)
            {
                RenderBounds = new Rectangle((int)position.X, (int)position.Y, Font.GetWidth(Text), Font.Height);
            }
        }
    }
}
